//
//  ViewController.swift
//  CAKeyframeAnimation淡出动画效果
//
//  Created by app on 2017/4/14.
//  Copyright © 2017年 app. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let v = UIView()
        v.backgroundColor = UIColor.red
        v.frame = CGRect(x: 100, y: 100, width: 200, height: 200)
        view.addSubview(v)
        
        
        let animation:CAKeyframeAnimation = CAKeyframeAnimation()
        
        animation.duration = 10.0
        
        animation.keyPath = "opacity"
        let valuesArray:[NSNumber] = [NSNumber(value:0.95 as Float),
                                      NSNumber(value:0.9 as Float),
                                      NSNumber(value:0.88 as Float),
                                      NSNumber(value:0.85 as Float),
                                      NSNumber(value:0.35 as Float),
                                      NSNumber(value:0.05 as Float),
                                      NSNumber(value:0.00 as Float)]
        animation.values = valuesArray
        animation.fillMode = kCAFillModeForwards
        animation.isRemovedOnCompletion = false
        v.layer.add(animation, forKey: nil)
        
        
    }
}

